using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Voodoo.Sauce.Core;
using Voodoo.Sauce.Internal.DebugScreen;
using Voodoo.Sauce.Internal.Extension;
using Voodoo.Sauce.Privacy;

namespace Voodoo.Sauce.Internal.GDPR.UI
{
	public class VoodooDebuggerInstructionPopup : MonoBehaviour
	{
		private const string _missingConsent = "You need to consent in order to have access to the debugger.";

		private const string _deviceIDPrefix = "Idfv :";

		private const string _secondPairPrefix = "Idfa :";

		[SerializeField]
		private GameObject _idParent;

		[SerializeField]
		private Text _deviceId;

		[SerializeField]
		private Button _copyButton;

		[SerializeField]
		private GameObject _secondPair;

		[SerializeField]
		private Text _secondPairText;

		[SerializeField]
		private Button _secondPairbutton;

		[SerializeField]
		private DebugPopup _debugPopup;

		private string _deviceIdValue;

		private string _secondPairValue;

		private void Start()
		{
			_copyButton.onClick.AddListener(delegate
			{
				_deviceIdValue.CopyToClipboard();
			});
			_secondPairbutton.onClick.AddListener(delegate
			{
				_secondPairValue.CopyToClipboard();
			});
		}

		private void OnEnable()
		{
			_debugPopup.Initialize(delegate
			{
				base.gameObject.SetActive(value: false);
			});
			base.transform.RefreshHierarchySize();
		}

		private void OnDisable()
		{
			_debugPopup.Dispose();
		}

		public void Show(string instruction, bool showUserId, UnityAction buttonCallback = null)
		{
			PrivacyCore privacy = VoodooSauceCore.GetPrivacy();
			DisplayInstructions(showUserId, privacy.GetVendorId());
			DisplaySecondInstructions(showUserId && privacy.HasAdsConsent(), privacy.GetAdvertisingId(forceZerosForLimitedAdTracking: false));
			base.gameObject.SetActive(value: true);
			_debugPopup.Initialize(instruction, buttonCallback);
		}

		private void DisplayInstructions(bool showUserId, string deviceId = null)
		{
			_idParent.SetActive(showUserId);
			_deviceIdValue = deviceId;
			_deviceId.text = "Idfv :" + _deviceIdValue;
		}

		private void DisplaySecondInstructions(bool showUserId, string deviceId = null)
		{
			_secondPair.SetActive(showUserId);
			_secondPairValue = deviceId;
			_secondPairText.text = "Idfa :" + _secondPairValue;
		}
	}
}
